package com.example.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.model.User;
import com.example.demo.service.TokenService;
import com.example.demo.util.R;

@RestController
public class JWTTest {
	@Autowired
	private TokenService tokenService;
	@RequestMapping("login")
	public R login(String username,String password) {
		System.out.println("username:"+username+"password:"+password);
		User user = new User();
		user.setName(username);
		
		if (user.getName().equals("joke")) {
			String token = tokenService.getToken(user);
			return R.ok(token);
		}
		return R.error("用户名或密码错误");
	}
}
